|
|
|
|
|
|
|
using the PlayMetaFile function. Pass the function the device context of the form or picture box and the metafile handle. You can use PlayMetaFile repeatedly to draw the image into several different forms or picture boxes if you like. |
|
|
|
|
|
|
|
|
Finally, when you have finished using the metafile, use the DeleteMetaFile function to free the resources used by the metafile. Note that this function does not actually delete the metafile if it is stored on disk. If you want to use a metafile stored on disk again, you can use the GetMetaFile function to reload it. If you want to remove the metafile physically from the disk, use Visual Basic's Kill statement. |
|
|
|
|
|
|
|
|
The following code shows the Visual Basic declarations for these metafile functions. |
|
|
|
 |
|
|
|
|
Private Declare Function CreateMetaFile Lib "gdi32" _
Alias "CreateMetaFileA" (ByVal lpString As String) As Long
Private Declare Function CloseMetaFile Lib "gdi32" _
Alias "CloseMetaFile" (ByVal hMF As Long) As Long
Private Declare Function GetMetaFile Lib "gdi32" _
Alias "GetMetaFileA" (ByVal lpFileName As String) As Long
Private Declare Function PlayMetaFile Lib "gdi32" _
Alias "PlayMetaFile" (ByVal hdc As Long, _
ByVal hMF As Long) As Long
Private Declare Function DeleteMetaFile Lib "gdi32" _
Alias "DeleteMetaFile" (ByVal hMF As Long) As Long
Private Declare Function SetWindowExtEx Lib "gdi32" ( _
ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, _
lpSize As SIZE) As Long
Private Type SIZE
cx As Long
cy As Long
End Type |
|
|
|
|
|
|
|
|
Example program Meta, shown in Figure 2.17, allows you to save and restore metafiles from disk. Click and drag the mouse to draw on the form. Select Save As from the File |
|
|
|
|
|
|
|
|
Figure 2.17
Program Meta saves and restores metafiles. |
|
|
|
|
|